<template>
  <div class="wrapper" ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<style scoped>
</style>

<script>
  import BScroll from 'better-scroll'

  export default {
    name: 'Scroll',
    //传参：父传子，写法：["形参1"[,"形参2"]]
    props: {
      probeType:{
        type:Number,
        default: 0
      },
      pullUpLoad:{
        type:Boolean,
        default: false
      }

    },
    created(){

    },
    mounted(){
      //创建BScroll对象
      this.scroll = new BScroll(this.$refs.wrapper, {
        click:true,
        probeType:this.probeType,
        pullUpLoad: this.pullUpLoad,
      })
      //监听滚动的位置
      this.scroll.on('scroll', (position) => {
        this.$emit('scroll' , position)
      })
      //监听上拉事件
      this.scroll.on('pullingUp', () => {
        this.$emit('pullingUp')
      })
    },
    data() {
      return {
        scroll: null,
      }
    },
    methods: {
      //跳转
      scrollTo(x,y,time=500) {
        this.scroll.scrollTo(x,y,time)
      },
      //上拉完成事件
      finishPullUp(){
        this.scroll.finishPullUp()
      },
      //刷新
      refresh(){
        this.scroll && this.scroll.refresh()
      }
    },
    components: {

    },
  }
</script>